# Copyright (c) Meta Platforms, Inc. and affiliates.

load("@fbcode_macros//build_defs:cpp_unittest.bzl", "cpp_unittest")
load("@fbcode_macros//build_defs:custom_unittest.bzl", "custom_unittest")
load("@fbcode_macros//build_defs:fbcode_configured_alias.bzl", "fbcode_configured_alias")
load("@fbcode_macros//build_defs:python_binary.bzl", "python_binary")
load("@fbsource//tools/build_defs:default_platform_defs.bzl", "get_host_target_platform")
load("../../defs.bzl", "zs_cxxbinary", "zs_fuzzers", "zs_unittest")

oncall("data_compression")

python_binary(
    name = "pytorch_model_generator",
    srcs = ["pytorch_model_generator.py"],
    labels = ["autodeps2_generated"],
    main_module = "data_compression.experimental.zstrong.custom_parsers.tests.pytorch_model_generator",
)

fbcode_configured_alias(
    name = "pytorch_model_generator_host",
    actual = ":pytorch_model_generator",
    platform = get_host_target_platform(),
)

zs_cxxbinary(
    name = "csv_main",
    srcs = [
        "csv_main.cpp",
    ],
    headers = [
        "DebugIntrospectionHooks.h",
    ],
    deps = [
        "../..:zstronglib",
        "../../cpp:openzl_cpp",
        "../csv:csv_parser",
        "../shared_components:numeric_graphs",
        "../shared_components:string_graphs",
    ],
)

cpp_unittest(
    # @autodeps-skip
    name = "test_zip_lexer",
    srcs = [
        "test_zip_lexer.cpp",
    ],
    deps = [
        "..:zip_lexer",
        "../..:zstronglib",
    ],
)

python_binary(
    name = "test_pytorch_model_compressor_bin",
    srcs = [
        "test_pytorch_model_compressor.py",
    ],
    main_module = "data_compression.experimental.zstrong.custom_parsers.tests.test_pytorch_model_compressor",
)

zs_unittest(
    name = "test_clustering",
    srcs = ["test_clustering.cpp"],
    headers = ["DebugIntrospectionHooks.h"],
    deps = [
        "../..:compress",
        "../..:decompress",
        "../../cpp:openzl_cpp",
        "../../tests:utils",
        "../../tests/datagen:datagen",
        "../csv:csv_parser",
    ],
)

custom_unittest(
    name = "test_pytorch_model_compressor",
    command = [
        "$(location :test_pytorch_model_compressor_bin)",
        "$(location :pytorch_model_generator)",
        "$(location ..:pytorch_model_compressor)",
    ],
    type = "simple",
    deps = [
        "..:pytorch_model_compressor",
        ":pytorch_model_generator",
        ":test_pytorch_model_compressor_bin",
    ],
)

zs_fuzzers(
    srcs = [
        "fuzz_pytorch_model_parser.cpp",
        "fuzz_zip_lexer.cpp",
    ],
    ftest_names = [
        ("PytorchModelParserTest", "FuzzCompress"),
        ("ZipLexerTest", "FuzzLexer"),
    ],
    generator = ":pytorch_model_generator_host",
    deps = [
        "..:pytorch_model_parser",
        "..:zip_lexer",
        "../..:zstronglib",
        "fbsource//xplat/security/lionhead/utils/lib_ftest:lib",
    ],
)
